package com.masterclient.app.businessmodule.vipmodule.card;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.utils.TextUtils;
import com.masterclient.app.R;
import com.masterclient.app.businessmodule.vipmodule.bean.ServiceOrder;
import com.masterclient.app.businessmodule.vipmodule.view.OrderView;
import com.masterclient.app.widget.CommonDialog;
import com.masterclient.app.widget.RefuseRefundDialog;

import butterknife.BindView;


/**
 * 售后订单
 */
public class OrderServiceCard extends IBaseCard<ServiceOrder>{//FCBaseCard<AddNewAddressPresenter,ServiceOrder> implements View.OnClickListener, AddNewAddressContract.View {
    @BindView(R.id.orderViwe)
    OrderView orderViwe;
    @BindView(R.id.btn1_tv)
    TextView btn1Tv;
    @BindView(R.id.btn2_tv)
    TextView btn2Tv;
    @BindView(R.id.btn_view)
    LinearLayout btnView;
    private int status;
    public OrderServiceCard(View itemView, Context context) {
        super(itemView, context);
    }

    @Override
    public void onBindViewHolder(ServiceOrder order, int i) {
        orderViwe.setOrder(order);
        //status = order.getStatus();
       // setOrderStatus();
    }

    /**
     * 设置订单状态
     */
    private void setOrderStatus() {
        if(0 == status){// 待审核
            setBtn("同意申请","拒绝申请");
        }else if(1 == status){// 待买家退货
            btnView.setVisibility(View.GONE);
        }else if(2 == status){// 待卖家收货
            setBtn("","确认收货");
        }else if(3 == status){// 待退款
            setBtn("同意退款","拒绝退款");
        }else if(4 == status){// 退款成功
            setBtn("","删除订单");
        }else if(5 == status){// 已关闭
            setBtn("","删除订单");
        }
    }

    /**
     * 设置按钮文字
     * @param text1
     * @param text2
     */
    private void setBtn(String text1,String text2){
        btnView.setVisibility(View.VISIBLE);
        if(TextUtils.isEmpty(text1))
            btn1Tv.setVisibility(View.GONE);
        else btn1Tv.setVisibility(View.VISIBLE);
        btn1Tv.setText(text1);
        btn2Tv.setText(text2);
    }

//    @Override
//    public void onClick(View v) {
//        switch (v.getId()){
//            case R.id.btn1_tv:
//                doOnclick1();
//                break;
//            case R.id.btn2_tv:
//                doOnclick2();
//                break;
//        }
//    }

    /**
     * 处理btn1点击事件
     */
    private void doOnclick1(){
        if(0 == status){// 待审核
            showCommonDialog("确定同意申请吗","确定","取消");
            // setBtn("同意申请","拒绝申请");
        }else if(2 == status){// 待卖家收货
            //setBtn("","确认收货");
        }else if(3 == status){// 待退款
            showCommonDialog("确定同意退款吗","确定","取消");
            // setBtn("同意退款","拒绝退款");
        }else if(4 == status){// 退款成功
            //setBtn("","删除订单");
        }else if(5 == status){// 已关闭
            // setBtn("","删除订单");
        }
    }

    /**
     * 处理btn1点击事件
     */
    private void doOnclick2(){
        if(0 == status){// 待审核
            showCommonDialog("确定拒绝申请吗","确定","取消");
           // setBtn("同意申请","拒绝申请");
        }else if(2 == status){// 待卖家收货
            showCommonDialog("确定已经收货了吗","确定","取消");
            //setBtn("","确认收货");
        }else if(3 == status){// 待退款
            showResufeDialog();
           // setBtn("同意退款","拒绝退款");
        }else if(4 == status){// 退款成功
            showCommonDialog("确定删除订单吗","确定","取消");
            //setBtn("","删除订单");
        }else if(5 == status){// 已关闭
            showCommonDialog("确定删除订单吗","确定","取消");
           // setBtn("","删除订单");
        }
    }

    /**
     * 显示拒绝退款dialog
     */
    private void showResufeDialog(){
        RefuseRefundDialog dialog = new RefuseRefundDialog(mContext);
        dialog.showDialog(new RefuseRefundDialog.SaveContentCallback() {
            @Override
            public void onSaveContent(String content) {

            }
        });
    }

    /**
     * 显示同意拒绝dialog
     */
    private void showCommonDialog(String title,String confirmTxt,String cancelTxt){
        new CommonDialog.Builder(mContext)
                .setTitle(title)
                .setOnConfirmClickListener(confirmTxt, new CommonDialog.OnConfirmClickListener() {
                    @Override
                    public void onConfirmClick() {
                    }
                })
                .setOnCancelClickListener(cancelTxt,null)
                .createDialog().show();
    }

}
